﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_QuestionManager_CombinationQuestion_Add_jiand : PowerCreator.LMS.Web.Base.BasePage
{
    ManagerQuestion objQuestion = new ManagerQuestion();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.AddQuestion))
        //{
        //    Script.ShowAndHistory("您没有添加试题的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {

            ViewState["QuestionID"] = Request.QueryString["QuestionID"].ToString();
            ViewState["Question_Father"] = objQuestion.LoadQuestion(int.Parse(ViewState["QuestionID"].ToString()));
            ViewState["TypeID"] = 6;
            ViewState["UserID"] = 10000;
            InitPage();
           
        }
    }
    protected override void InitPage()
    {
        lab_TitleInfo.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_ContentTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_QuestionCount.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionContent", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_RightAnswer.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionOption", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_RightAnswer.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_RightAnswer", PowerCreator.LMS.Language.LanagetItemType.Page);

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        VOQuestion voQuestion_Father = new VOQuestion();
        voQuestion_Father = (VOQuestion)ViewState["Question_Father"];
        VOQuestion voQuestion = new VOQuestion();
        voQuestion.QuestionIsFather = 0;
        voQuestion.FKQuestionCourseID = voQuestion_Father.FKQuestionCourseID;
        voQuestion.QuestionCreateID = int.Parse(ViewState["UserID"].ToString());
        voQuestion.QuestionCreateTime = DateTime.Now;

        voQuestion.QuestionAnswer = "";            //
        voQuestion.QuestionDefaultScore = voQuestion_Father.QuestionDefaultScore;
        voQuestion.QuestionDiffculty = voQuestion_Father.QuestionDiffculty;
        voQuestion.QuestionKen = voQuestion_Father.QuestionKen;


        voQuestion.QuestionClass = 3;
        voQuestion.QuestionContent = txtQuestionContent.Value;
        voQuestion.QuestionParse = txtQuestionParse.Text;
        voQuestion.FKQuestionTypeID = int.Parse(ViewState["TypeID"].ToString());
        voQuestion.QuestionState = voQuestion_Father.QuestionState;         //禁用1,启用2

        try
        {
            int questionID = 0;
            if (objQuestion.CreateQuestionOptionList(voQuestion, null, ref questionID))
            {
                if (voQuestion_Father.QuestionItemList != "")
                {
                    voQuestion_Father.QuestionItemList = voQuestion_Father.QuestionItemList + "$" + questionID.ToString();
                }
                else
                {
                    voQuestion_Father.QuestionItemList = questionID.ToString();
                }
                if (objQuestion.UpdateQuetion(voQuestion_Father))
                {
                    Script.Alert(GetLanageValueByKey("Msg_ManagerQuestion_WorkOK", PowerCreator.LMS.Language.LanagetItemType.Page));
                    Script.ReloadParent();
                    Script.CloseMe();
                }

            }
            else
            {
                Script.Alert(GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page));
            }
        }
        catch
        {
            Script.ShowAndRedirect(this, GetLanageValueByKey("Msg_ManagerQuestion_WorkNo", PowerCreator.LMS.Language.LanagetItemType.Page), "ManagerQuestionInfo.aspx");
        }

    }



}
